# v412 Schema Design Review Note v412 adds `Project Documentation/Architecture/WORKSPACE_TYPE_SUBSCRIPTION_SCHEMA_DESIGN_REVIEW.md` as the active schema design review before Prisma changes. It confirms workspace type/account class, plan visibility, trial policy, registration state, owned interface/invited portal ownership, broker distribution limits, internal load-board access, billing gate overrides, and Super Admin audit requirements. v412 does not change Prisma. # v411 Implementation Note — Super Admin Workspace Type Review Surface v411 adds /admin/workspaces/types as the first Super Admin control surface based on this architecture. It does not change Prisma. Workspace type is still inferred from current records, and the page explicitly shows that stored workspace type, account class, plan visibility, trial policy, portal ownership, broker distribution limits, and Super Admin override/audit records remain future schema work. # Membership Subscription, Trial, and Workspace-Type Architecture Status: Active architecture planning source Introduced: v410 Scope: workspace type, paid workspace vs owned interface, registration, trial policy, plan visibility, entitlements, portal access, broker load distribution limits, internal load-board access, Stripe handoff, billing gates, Super Admin visibility, and future Prisma representation Product UI changed in v410: No Prisma schema changed in v410: No ## Purpose This plan decides how Dispatch Spot should represent workspace type, membership subscription, trial status, plan visibility, entitlements, add-ons, invited interfaces, and billing gates before changing sign-up UI or Prisma. The goal is to prevent the same kind of architecture drift that appeared during the notification track. Super Admin must control the platform, subscriptions, provider availability, workspace type behavior, usage limits, support, and audit. Workspace Admin must control workspace business behavior. Owned interfaces such as drivers must not accidentally become separate paying customers. ## v410 decision summary 1. Every paid business workspace should have a subscription record from creation, even during trial. 2. Drivers do not need independent subscriptions by default. They are owned user/interface roles under the workspace they drive for. 3. Small shipper/customer portals and carrier-response portals should usually be owned by the inviting workspace, not separately billed. 4. Independent Dispatcher, Company/Fleet, Carrier/Owner-Operator, Freight Broker, and large Shipper workspaces are paid workspace types. 5. Workspace type selection should happen during registration before workspace creation. 6. Plan selection should happen during registration, but trial access can start before payment collection unless the selected plan or feature requires a paid billing method. 7. The initial standard trial policy should be 14 days, configurable by Super Admin later. 8. Stripe should be the Super Admin platform billing provider for Dispatch Spot SaaS subscriptions. 9. Provider setup, integration credentials, phone inventory, load-board provider setup, SendGrid-like email distribution provider setup, AI provider setup, and Stripe platform setup belong under Super Admin integration/platform controls, with workspace-level operational settings separate. 10. Prisma does not need to change in v410, but the current schema is not complete enough for the final workspace-type/subscription model. ## Workspace/account classification model Dispatch Spot should treat accounts as one of four major classes. | Class | Meaning | Examples | Billing treatment | | --- | --- | --- | --- | | Paid workspace | A business account that owns records, users, settings, integrations, usage, and subscription status. | Dispatcher, Company/Fleet, Carrier/Owner-Operator, Freight Broker, Large Shipper | Requires trial, paid subscription, comp, enterprise, or internal billing state. | | Owned interface | A user interface owned by a paid workspace. | Driver interface, staff account, road-only user | No independent subscription by default. Counts against the owning workspace's limits if the plan requires it. | | Invited portal | A limited outside-party collaboration interface invited by a paid workspace. | Small shipper/customer portal, carrier response portal, document upload portal | Usually no independent subscription. Access is governed by the inviting workspace plan and permissions. | | Platform layer | A shared Dispatch Spot platform service used across workspaces. | Internal load board, provider scheduler, platform notifications | Access is governed by plans, add-ons, verification, Super Admin rules, and platform policy. | ## Workspace types and subscription behavior | Workspace or interface | Subscription required by default? | Owner of records/settings | Primary Super Admin concern | | --- | --- | --- | --- | | Dispatcher Workspace | Yes | Dispatch company workspace | Seats, trucks/carriers served, phone numbers, CORI, load-board access, notification delivery, billing status. | | Company/Fleet Workspace | Yes | Fleet/company workspace | Users, trucks, drivers, phone numbers, routing/weather, accounting, driver interfaces, billing status. | | Carrier/Owner-Operator Workspace | Yes when independent | Carrier/owner-operator workspace | Simplified plan, truck/driver limits, phone/CORI/routes, billing status. | | Driver Interface | No | Owning workspace | Permissions, field/mobile access, earnings visibility, alerts, safety, support. | | Freight Broker Workspace | Yes | Brokerage workspace | Shipper/customer records, carrier list, load blasts, load-board posting, email/provider limits, compliance, billing status. | | Shipper/Customer Portal | Usually no | Inviting broker/fleet/dispatcher workspace | Privacy boundary, shipment visibility, document permissions, support. | | Large Shipper Workspace | Optional paid product later | Shipper workspace | Shipment volume, quote requests, integrations, billing status. | | Carrier Response Portal | Usually no | Inviting broker workspace or load-board transaction | Rate response, document exchange, opt-out/suppression, access limits. | | Dispatch Spot Internal Operations Workspace | Internal only | Dispatch Spot | Support work, onboarding, implementation, incidents, customer success. | | Internal Load Board | Platform layer | Dispatch Spot platform | Access rules, postings, responses, abuse prevention, billing/add-ons. | ## Registration workflow decision The standard registration flow should be: 1. User creates account. 2. User selects workspace type. 3. User enters basic business/workspace details. 4. User selects a plan that is visible for that workspace type. 5. Dispatch Spot creates the workspace and a trial subscription record immediately. 6. Dispatch Spot creates or prepares a Stripe customer relationship for platform billing. 7. User enters the workspace in trial mode with plan-limited features. 8. Workspace Admin completes setup in Workspace Settings and Workspace Integrations. 9. Before trial ends, the system prompts for paid activation through Stripe. 10. If trial expires, access is limited by the expired-trial rules until the user pays, gets an extension, or Super Admin overrides the account. ## Trial policy Initial trial policy: - standard trial length: 14 days; - trial starts when the paid workspace is created; - trial is attached to `WorkspaceSubscription`, not to a single user; - Super Admin can later extend, shorten, cancel, or comp a trial; - users created inside the workspace inherit the workspace trial state; - drivers and invited portal users do not receive separate trials; - trial access should be useful enough to evaluate the product but guarded for high-cost and abuse-prone features. ## Trial feature posture During trial, the workspace should generally be allowed to: - create records; - invite a limited team; - test CORI surfaces; - preview notifications and digests; - connect integrations in Workspace Integrations; - test email provider readiness; - use limited route/weather checks if provider costs are controlled; - view plan limits and upgrade options. During trial, the workspace should be guarded or limited for: - automatic notification digest sending; - urgent SMS sends; - live phone number assignment; - live call/SMS volume; - broker load-blast volume; - external load-board posting; - large email distribution sends; - high-cost AI usage; - bulk imports or exports; - marketplace posting/response automation. A paid billing method or explicit Super Admin approval may be required before high-cost features go live. ## Plan visibility model Plans should not be shown to every workspace type equally. Plan visibility should support: - visible workspace types; - hidden/internal plans; - trial-eligible plans; - plan family, such as dispatcher, fleet, carrier, broker, shipper, enterprise; - public plans versus Super Admin-assigned plans; - test/internal plans; - enterprise/custom plans; - grandfathered plans. Examples: | Plan family | Visible to | Notes | | --- | --- | --- | | Dispatcher plans | Dispatcher Workspace | Focus on trucks/carriers served, phone, CORI Mail, dispatch operations. | | Fleet plans | Company/Fleet Workspace | Focus on trucks, drivers, compliance, route/weather, accounting. | | Owner-Operator plans | Carrier/Owner-Operator Workspace | Focus on one/small truck count, routes, documents, earnings. | | Broker plans | Freight Broker Workspace | Focus on carrier list, load distribution, load-board access, margins, documents. | | Shipper plans | Large Shipper Workspace later | Focus on shipment requests, quote volume, shipment visibility, integrations. | | Internal plans | Dispatch Spot internal workspaces | Not public. Assigned by Super Admin only. | ## Entitlement dimensions The entitlement engine should eventually handle both feature access and usage limits. Core entitlement groups: | Group | Example limits/features | | --- | --- | | Seats and users | included admin/users, extra paid users, invited portal users, deactivated users. | | Drivers | active drivers, invited driver interfaces, earnings visibility. | | Trucks/assets | active trucks, trailers/equipment, archived trucks. | | Phone system | included phone numbers, extra phone numbers, call/SMS access, urgent SMS. | | Messaging/email | notification email, CORI Mail send, broker carrier blast sends, daily digest sends. | | Broker distribution | carrier list size, email sends per month, load-board postings, external board integrations. | | Internal load board | search access, posting access, response limits, featured posts, verification required. | | CORI/AI | Ask CORI access, CORI Briefing, CORI Mail, CORI Financial, role-specific CORI capabilities, usage limits. | | Routes/weather | route planning, map checks, weather checks, traffic advisories, driver route support. | | Documents/storage | document count/storage, external storage integrations, portal document upload. | | Accounting/billing | invoicing, QuickBooks sync, financial reports, settlements, margin reporting. | | Reports/analytics | advanced dashboards, export, performance reports, revenue metrics. | | Support | support tier, onboarding help, implementation, priority support. | ## Add-ons Add-ons should be managed by Super Admin and sold through Stripe when billing is live. Common add-ons: - extra users/seats; - extra active trucks; - extra business phone numbers; - additional SMS/call package or usage rules; - advanced CORI/AI usage; - external load-board posting package; - broker carrier email distribution package; - internal load-board featured postings; - QuickBooks/accounting integration; - advanced reports; - implementation/support package. ## Expired-trial behavior When a paid workspace trial expires, the app should move into a limited state, not immediately destroy work. Allowed after trial expiration: - sign in; - view billing/plan screen; - update payment/activate subscription; - contact support; - view limited existing records for continuity; - export data if policy allows; - receive safety-critical notices. Blocked or limited after trial expiration: - creating new loads; - assigning new loads; - sending CORI Mail; - sending notification digests; - sending SMS; - making platform-managed calls; - posting to load boards; - sending broker load blasts; - inviting additional users; - using high-cost AI/provider features; - changing provider setup except where needed to restore billing or support. Super Admin should be able to: - extend trial; - comp the workspace; - reactivate; - suspend; - cancel; - force billing hold; - add support notes; - see why access is limited. ## Billing status gates Workspace access must be resolved through subscription and entitlement status, not scattered page checks. Recommended gate states: | State | Meaning | Normal behavior | | --- | --- | --- | | Trial active | Trial is not expired. | Allow plan-limited evaluation. | | Active paid | Stripe/manual billing is active. | Allow purchased plan and add-ons. | | Past due | Payment problem. | Show billing warning; restrict high-cost or risky actions after grace period. | | Paused | Manually paused by Super Admin or billing policy. | Limit most write actions. | | Canceled | Subscription ended. | Lock workspace except billing/support/data policy access. | | Comp/internal | Super Admin-owned special status. | Allow according to assigned plan/override. | ## Stripe handoff Stripe is the platform billing provider for Dispatch Spot SaaS subscription payments. Recommended sequence: 1. Registration creates workspace and trial subscription. 2. Stripe customer is created or prepared for the workspace billing owner. 3. Stripe checkout/customer portal handles paid activation, payment method, plan upgrade, downgrade, cancellation, and billing details. 4. Stripe webhooks update `WorkspaceSubscription` status. 5. Entitlement engine recalculates access from plan, add-ons, billing state, and Super Admin overrides. 6. Workspace pages show simple access messages. Super Admin shows detailed status and sync health. Important billing separation: - Super Admin platform subscriptions use Stripe to bill Dispatch Spot SaaS customers. - Workspace Admin dispatcher-service billing to carriers may use a separate Stripe path later. - Carrier/company payments from brokers/shippers often use factoring or Net 30 and should not be forced into the platform subscription Stripe path. - Twilio bills Dispatch Spot. Dispatch Spot bills workspaces through Stripe via plan limits, add-ons, and usage rules. ## Invited driver/customer/carrier portal access Owned and invited interfaces should be represented as access under an owning workspace. Driver access should include: - assigned truck/load visibility; - current and upcoming load details; - route progress; - weather/traffic advisories; - truck stop/refuel/rest planning; - document upload; - dispatch communication; - limited Ask CORI; - earnings visibility only if the owning workspace allows it. Customer/shipper portals should include: - shipment request or shipment status; - document upload/download; - appointment and tracking visibility; - messages; - invoice/claim visibility where allowed; - no internal dispatcher/fleet notes. Carrier response portals should include: - load offer details; - rate response; - document exchange; - award/decline status; - opt-out/suppression handling for email distribution; - no broker internal margin notes. ## Broker load distribution limits Freight Broker Workspace must eventually support full brokerage operations, including distribution of available loads. Distribution channels: - email to carrier list through a SendGrid-like provider; - external load-board posting integrations; - Dispatch Spot internal load board; - direct carrier response portal links; - CORI-assisted carrier email drafting and follow-up. Required controls before live expansion: - carrier relationship status; - unsubscribe/opt-out/suppression list; - bounce/failure handling; - send history; - load detail review before send; - rate/margin privacy controls; - per-plan send limits; - per-plan load-board posting limits; - abuse monitoring; - Super Admin usage visibility; - provider cost visibility; - clear billing/add-on rules. ## Internal load-board access The future Dispatch Spot internal load board should be a platform layer, not just a broker page. Access should be controlled by: - workspace type; - subscription plan; - verification status; - posting/search entitlements; - billing state; - anti-abuse rules; - Super Admin policy; - workspace trust/safety status. Freight brokers may post loads. Carriers, owner-operators, fleets, and dispatchers may search or respond depending on plan and verification. Shippers may request freight movement or post only if a later product tier allows it. ## Super Admin visibility and controls Super Admin must be able to see and control: - workspace type; - account class: paid workspace, owned interface, invited portal, platform layer, internal; - trial status; - subscription plan; - Stripe customer/subscription status; - billing status gates; - plan visibility and assignment; - entitlement limits and add-ons; - over-limit states; - invited driver/customer/carrier access counts; - broker load distribution limits and usage; - internal load-board access and usage; - provider readiness by workspace; - phone number assignments and usage; - email blast provider health and usage; - CORI/AI access and usage; - route/weather/provider usage; - support notes; - admin interventions; - suspension/reactivation/cancellation history; - audit events. ## Current Prisma schema review v410 does not change Prisma. This review records what exists and what is missing before schema work begins. Current schema strengths: - `Organization` represents a tenant/workspace. - `WorkspaceSubscription` is already one-to-one with `Organization`. - `SubscriptionPlan` already stores core limits for users, trucks, and phone numbers. - `WorkspaceSubscription` already stores trial end, billing provider status, Stripe identifiers, override JSON, add-on JSON, and provider sync state. - `User` belongs to an `Organization` and can link to a `Driver`. - `UserRole` already includes company driver and owner-operator roles. - Integration accounts exist through `WorkspaceIntegrationAccount`. - Notification, outbound email, text, CORI Mail, and Stripe webhook records already exist for several audit paths. Current schema gaps before the final model: - `Organization` does not yet have a durable workspace type field. - There is no clear enum for paid workspace vs owned interface vs invited portal vs platform/internal layer. - `SubscriptionPlan` does not yet define visible workspace types or public/hidden/internal plan visibility. - Trial policy is not modeled as configurable Super Admin policy. - Entitlements beyond users/trucks/phone numbers are mostly booleans or JSON, not normalized capability/limit records. - There is no dedicated usage counter/event model for plan limits such as email blasts, load-board posts, CORI usage, SMS/call usage, or external provider usage. - Driver access is partially represented through `User.linkedDriverId`, but the final owned-interface permission model is not complete. - Invited customer/shipper/carrier portal access does not yet have a dedicated model. - Broker carrier-list distribution, suppression lists, load-blast sends, and load-board posting records are not yet fully modeled. - Internal load-board access, posting, responses, and awards are not yet fully modeled. - Super Admin override history and entitlement-change audit should be more explicit before live billing enforcement. ## Future schema direction, not implemented in v410 Recommended future additions: - `WorkspaceType` enum for `DISPATCHER`, `COMPANY_FLEET`, `CARRIER_OWNER_OPERATOR`, `FREIGHT_BROKER`, `SHIPPER`, `INTERNAL_OPERATIONS`. - `WorkspaceAccountClass` enum for `PAID_WORKSPACE`, `OWNED_INTERFACE`, `INVITED_PORTAL`, `PLATFORM_LAYER`, `INTERNAL` if this is modeled separately from workspace type. - `Organization.workspaceType` and possibly `Organization.accountClass`. - Plan visibility fields such as `visibleWorkspaceTypesJson`, `isPublic`, `isTrialEligible`, and `planFamily`. - Normalized plan entitlement/add-on records when JSON becomes too limiting. - `WorkspaceUsageEvent` or `WorkspaceUsageCounter` for load-board posts, email distribution sends, CORI usage, SMS/call usage, storage, and provider costs. - `WorkspaceAccessInvite` for driver/customer/carrier/portal invitations and acceptance state. - `WorkspacePortalAccess` or equivalent for ongoing limited outside-party access. - Broker distribution models for carrier list members, suppression/opt-out records, load distribution batches, recipient events, and carrier responses. - Internal load-board models for posting, response, award, verification, abuse flags, and billing impacts. - Super Admin audit records for plan changes, entitlement overrides, trial extension, comping, suspension, and reactivation. ## Implementation order recommendation 1. Finish planning and approve this v410 architecture. 2. Build a Super Admin workspace type/subscription overview shell using existing data only. 3. Add schema for workspace type and plan visibility. 4. Update registration to select workspace type and plan before workspace creation. 5. Add trial policy and expired-trial gates. 6. Add entitlement checker expansion and visible Super Admin plan/limit controls. 7. Add Driver/portal ownership improvements. 8. Add Freight Broker distribution architecture and safe email-provider integration. 9. Add internal load-board access/posting models. 10. Add Stripe checkout/customer portal/webhook hardening for live subscriptions. ## Guardrails - Do not build Super Admin pages that are disconnected from workspace type, subscription, entitlement, integration, usage, support, or audit requirements. - Do not make drivers independent paying workspaces by default. - Do not put plan selection, provider setup, or billing internals on daily work pages. - Do not expose Stripe, Twilio, SendGrid-like, load-board, AI, weather, maps, or SMTP secrets in browser-facing pages. - Do not enable high-cost automation until provider readiness, entitlement checks, billing gates, and audit records are in place. ## v413 implementation note The Phase 1 schema foundation from this design review is now implemented. The new durable fields/models are: - `WorkspaceType`; - `WorkspaceAccountClass`; - nullable `Organization.workspaceType`; - nullable `Organization.accountClass`; - `SubscriptionPlanFamily`; - `SubscriptionPlanVisibility`; - `SubscriptionPlan.planFamily`; - `SubscriptionPlan.planVisibility`; - `SubscriptionPlan.visibleWorkspaceTypesJson`; - `SuperAdminAuditEvent`. This is a foundation only. Do not use these fields as hard entitlement gates until Super Admin classification workflow, registration flow, plan visibility enforcement, billing gates, and audit-backed override behavior are explicitly designed and built. ## v414 update — existing workspace classification Super Admin now has a guarded classification workflow on `/admin/workspaces/types` for existing workspaces. Classification stores workspace type and account class, and writes audit events. Classification is a prerequisite review step before registration-time workspace type selection, plan visibility enforcement, paid workspace gates, owned interface/portal modeling, broker distribution limits, and internal load-board access are activated. ## v420 signup-staging review and audit note As of v420, Super Admin has a review dashboard on `/admin/subscriptions` that checks the active review-only signup staging path. The review dashboard must remain Super Admin-only and should be used before any future registration expansion. It shows: - signup workspace-type coverage for Dispatcher, Company / Fleet, Carrier / Owner-Operator, and Freight Broker; - staged Public and Invite only plan counts by workspace type; - workspace types that still fall back to the safe default plan; - recent review-only signup audit records; - whether each audited signup used a staged plan match or default fallback. Public signup creation now records a `REGISTRATION_SIGNUP_STAGED_WORKSPACE_CREATED` Super Admin audit event. That audit record is for support and governance only. It does not activate checkout, payment collection, hard billing gates, broker distribution, portal ownership, or internal load-board access. ## v423 guarded Stripe checkout preparation update The first checkout-preparation step is Super Admin review-only. Before any checkout session route is built, Super Admin can now see whether Stripe environment values are present, which staged signup plans have Stripe product and monthly price IDs, which signup workspace types lack Stripe-ready plans, and whether recent review-only trial workspaces have trial end dates. The checkout path remains locked at this stage. No card collection, checkout session creation, customer portal access, live payment collection, hard billing gates, broker distribution limits, owned portal rules, or internal load-board access are activated by this preparation review. ## v424 locked checkout route scaffold update The first route-level checkout scaffold now exists at `/api/subscriptions/stripe-checkout`, but it remains locked in test-mode review posture. The route can review workspace eligibility, trial subscription readiness, plan Stripe readiness, and environment posture. It does not create checkout sessions, collect cards, create customer portal sessions, create invoices, create charges, enforce hard billing gates, activate broker distribution limits, change owned portal rules, or open internal load-board access. This gives future checkout work a stable route path without activating payment behavior. ## v426 Workspace Admin checkout locked-state review update Workspace Admin Billing now shows a locked subscription checkout review card. This is intentionally visible but non-operational. The card confirms that the future checkout path is still locked, shows plain subscription readiness state, and allows a safe locked-state check that does not open a payment page. It does not expose Stripe credentials or raw provider IDs on the Billing page. Checkout session creation, card collection, customer portal sessions, invoice creation, charge creation, hard billing gates, broker distribution limits, owned portal rules, and internal load-board access remain inactive.